package com.layne.jeasy.api.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.layne.jeasy.api.entity.Member;
import com.layne.jeasy.api.servicre.MemberService;
import com.layne.jeasy.common.util.RedisUtil;

/**
 * @author laynezhu
 * @date 2019/05/13
 */
@Controller
@RequestMapping("/api/member")
public class MemberController {
    private static Logger logger = LoggerFactory.getLogger(MemberController.class);

    @Resource
    private MemberService memberService;
    
    @Resource
    private RedisUtil redisUtil;
    
    @RequestMapping(value = "/sayHello")
    @ResponseBody
    public JSONObject sayHello() {
        logger.info("begin to say hello!");
        JSONObject resultJson = new JSONObject();
        resultJson.put("status", "200");
        resultJson.put("data", "hello,world!");
        return resultJson;

    }
    
    @RequestMapping(value = "/query",method = RequestMethod.GET)
    @ResponseBody
    public JSONObject query(@RequestParam(value = "id") int id) {
        Member member = memberService.getMemberById(id);
        JSONObject resultJson = new JSONObject();
        resultJson.put("status", "200");
        resultJson.put("data", member);
        redisUtil.set(member.getId().toString(), member.getUserName());
        return resultJson;
    }
        
    
}
